//
//  HttpRequestList.m
//  测试
//
//  Created by user on 16/5/14.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "HttpRequestList.h"
#import "TZActiveItem.h"
#import "TZEssenceItem.h"
#import "TZBaseItem.h"
#import "TZAdItem.h"
#import "TZCommentItem.h"
#import "TZDataItem.h"

@implementation HttpRequestList

/**
 *  请求电影列表
 *
 *  @param url        无参,url改变
 *  @param paramaters 参数
 *  @param success    成功回调
 *  @param failure    失败回调
 */
+ (void)requestMovieList:(NSString *)url paramaters:(id)paramaters success:(void (^)(id))success failure:(void (^)(NSError *))failure
{

    url = [NSString stringWithFormat:@"api/movie/list/%@",url];
    [HttpTool GET:url parameters:nil success:^(id responseObject) {
        if (success) success(responseObject);
    } failure:^(NSError *error) {
        if (failure) failure(error);
    }];
}

/*************************** 广告模块请求 **********************************/
+ (void)requestAdvertising:(NSString *)url paramaters:(id)paramaters success:(void (^)(TZAdItem* ))success :(void (^)(NSError *))failure{
    
    AFHTTPSessionManager *mng = [AFHTTPSessionManager manager];
    mng.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
    [mng GET:url parameters:paramaters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
        if (success) success([TZAdItem mj_objectWithKeyValues:responseObject[@"ad"][0]]);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure)   failure(error);

    }];
}


/*************************** 我的模块请求 **********************************/

+ (void)requestActiveList:(NSString *)url paramaters:(id)paramaters success:(void (^)(NSArray *))success failre:(void (^)(NSError *))failure{
    
    
    
    [HttpTool GET:url parameters:paramaters success:^(id responseObject) {
        success([TZActiveItem mj_objectArrayWithKeyValuesArray:responseObject[@"square_list"]]);
    } failure:^(NSError *error) {
        if (failure) failure(error);
    }];
}
/*************************** 精华模块请求 **********************************/
+ (void)requestEssenceList:(NSString *)url paramaters:(id)paramaters success:(void (^)(TZBaseItem *))success failure:(void (^)(NSError *))failure{
    
    [HttpTool GET:url parameters:paramaters success:^(id responseObject) {
        [TZEssenceItem mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
            return @{@"ID" : @"id"};
        }];
       
        [TZBaseItem mj_setupObjectClassInArray:^NSDictionary *{
            return @{ @"list" : [TZEssenceItem class]};
        }];
        
        success([TZBaseItem mj_objectWithKeyValues:responseObject]);
    } failure:^(NSError *error) {
        if (failure) failure(error);

    }];
}

+ (void)requestEssenceDetail:(NSString *)url paramaters:(id)paramaters success:(void (^)(TZCommentItem *))success failure:(void (^)(NSError *))failure{
    
    
    [HttpTool GET:url parameters:paramaters success:^(id responseObject) {

        
        [TZCommentItem mj_setupObjectClassInArray:^NSDictionary *{
            return @{
                     @"data" : [TZDataItem class],
                     @"hot" :[TZDataItem class]
                     };
        }];
        success([TZCommentItem mj_objectWithKeyValues:responseObject]);
    } failure:^(NSError *error) {
        if (failure) failure(error);
    }];
    
}

@end
